﻿using EventModel;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ExamEventBus
{
    public class ExamEventRepository : IEventRepository
    {
        public async Task<IEnumerable<IExamModel>> GetEvents()
        {
            return await Task.Run(() =>
            {
                return SugarBase.Exec(db =>
                 {
                     var list = db.Queryable<marking_log>().Where(t => t.status == 0).ToList();
                     Console.WriteLine(list.Count);
                     return list as IEnumerable<IExamModel>;
                 });
            });
        }

        public async Task<bool> UpdateEventStatus(IMessage model)
        {
            return await Task.Run(() =>
            {
                return SugarBase.Exec(db =>
                 {
                     string sql = $"update marking_log set status=1 where id='{model.id}'";
                     Console.WriteLine(sql);
                     return db.Ado.ExecuteCommand(sql) > 0;
                 });
            });
        }

    }
}
